package cn.edu.scau.cmi.chenyiqiu.spring.hibernate.factory;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class HibernateSessionFactory {
	private static  HibernateSessionFactory  hibernateUtil=null;
	private static SessionFactory sessionFactory;
	private static Session session;
	public HibernateSessionFactory() {
		
	}
	public HibernateSessionFactory getInstance() {
		if(hibernateUtil==null)
		{
			hibernateUtil=new HibernateSessionFactory();
		}
		return hibernateUtil;
	}
	
	public static SessionFactory getfactory() {
		if(sessionFactory==null) {
			Configuration cfg=new Configuration().configure();
			sessionFactory=cfg.buildSessionFactory();
		}
		return sessionFactory;
	}
	
	public static Session getSession() {
		if(session==null)
		{
			session=getfactory().openSession();
		}
		return session;
		
	}
	
}
